home *** CD-ROM | disk | FTP | other *** search
/ Borland JBuilder 6 / jbuilder6.iso / Taiji Applet Pack v2.7 / Presentation / Presentation.class (.txt) < prev    next >
Encoding:
Java Class File  |  2001-11-06  |  10.2 KB  |  492 lines

  1. import java.applet.Applet;
  2. import java.applet.AudioClip;
  3. import java.awt.Color;
  4. import java.awt.Component;
  5. import java.awt.Cursor;
  6. import java.awt.Font;
  7. import java.awt.FontMetrics;
  8. import java.awt.Graphics;
  9. import java.awt.Image;
  10. import java.awt.MediaTracker;
  11. import java.awt.event.MouseEvent;
  12. import java.awt.event.MouseListener;
  13. import java.net.MalformedURLException;
  14. import java.net.URL;
  15. import java.net.URLEncoder;
  16.  
  17. public class Presentation extends Applet implements Runnable, MouseListener {
  18.    private Thread thread;
  19.    private Image buffer;
  20.    private Image[] image;
  21.    // $FF: renamed from: b java.awt.Graphics
  22.    private Graphics field_0;
  23.    private boolean loaded;
  24.    // $FF: renamed from: N int
  25.    private int field_1;
  26.    // $FF: renamed from: wi int
  27.    private int field_2;
  28.    // $FF: renamed from: he int
  29.    private int field_3;
  30.    private int wiIm;
  31.    private int heIm;
  32.    private int pause = 50;
  33.    private int minPause = 2000;
  34.    private int maxPause = 5000;
  35.    private int NWCells;
  36.    private int NHCells;
  37.    private int cellsSpacing = 2;
  38.    // $FF: renamed from: Nt int
  39.    private int field_4;
  40.    private int textPause = 2000;
  41.    private int[][] mat;
  42.    private String statusBarText;
  43.    private AudioClip sound;
  44.    private AudioClip clicSound;
  45.    private AudioClip enterSound;
  46.    private boolean loopSound;
  47.    private String link;
  48.    private String text;
  49.    private String[] lines;
  50.    // $FF: renamed from: fm java.awt.FontMetrics
  51.    private FontMetrics field_5;
  52.    private String enterText;
  53.    private int wiText;
  54.    private int textHeight = 10;
  55.    private Color textColor;
  56.  
  57.    public String getAppletInfo() {
  58.       return "Name: Presentation\r\nAuthor: Taiji Software\r\n";
  59.    }
  60.  
  61.    public Presentation() {
  62.       ((Component)this).addMouseListener(this);
  63.    }
  64.  
  65.    public void register() {
  66.       try {
  67.          URL u = new URL("http://www.taijisoftware.com");
  68.          ((Applet)this).getAppletContext().showDocument(u, "_blank");
  69.       } catch (Exception e) {
  70.          System.out.println(e);
  71.          this.stop();
  72.       }
  73.    }
  74.  
  75.    public void init() {
  76.       String codeBase = null;
  77.  
  78.       try {
  79.          codeBase = (new URL(((Applet)this).getCodeBase().toString())).getHost();
  80.          System.out.println("Copyright 1999, 2001 Taiji Software(tm)\nYour domain name is : " + codeBase);
  81.          codeBase = codeBase.toUpperCase();
  82.       } catch (Exception var9) {
  83.       }
  84.  
  85.       if (!((Applet)this).getCodeBase().toString().toUpperCase().startsWith("FILE") || ((Applet)this).getParameter("debug") != null) {
  86.          String regCode = ((Applet)this).getParameter("registration_code");
  87.          if (regCode == null) {
  88.             regCode = ((Applet)this).getParameter("reg_domain");
  89.             if (regCode == null) {
  90.                this.register();
  91.             } else {
  92.                if (regCode.length() == codeBase.length() + 4 && !codeBase.startsWith("WWW.")) {
  93.                   codeBase = "WWW." + codeBase;
  94.                } else if (regCode.length() == codeBase.length() - 4 && codeBase.startsWith("WWW.")) {
  95.                   codeBase = codeBase.substring(4);
  96.                }
  97.  
  98.                char[] chars = new char[codeBase.length()];
  99.                codeBase.getChars(0, codeBase.length(), chars, 0);
  100.                String key = new String("haricot");
  101.                char[] chars2 = new char[key.length()];
  102.                key.getChars(0, key.length(), chars2, 0);
  103.  
  104.                for(int i = 0; i < codeBase.length(); ++i) {
  105.                   int j;
  106.                   if (i >= key.length()) {
  107.                      j = i - key.length() * (i / key.length());
  108.                   } else {
  109.                      j = i;
  110.                   }
  111.  
  112.                   chars[i] += chars2[j];
  113.                   chars[i] = (char)(chars[i] - chars[i] / 26 * 26 + 97);
  114.                }
  115.  
  116.                String res = new String(chars);
  117.                if (!res.equalsIgnoreCase(regCode)) {
  118.                   this.register();
  119.                }
  120.             }
  121.          } else if (!regCode.equals("settevercsedegnamiaj") && !regCode.equals("8078")) {
  122.             this.register();
  123.          }
  124.       }
  125.  
  126.       this.getParameters();
  127.       if (this.sound != null) {
  128.          if (this.loopSound) {
  129.             this.sound.loop();
  130.             return;
  131.          }
  132.  
  133.          this.sound.play();
  134.       }
  135.  
  136.    }
  137.  
  138.    public void getParameters() {
  139.       this.field_2 = ((Component)this).getSize().width;
  140.       this.field_3 = ((Component)this).getSize().height;
  141.       this.text = ((Applet)this).getParameter("text");
  142.       String s = ((Applet)this).getParameter("pause");
  143.       if (s != null) {
  144.          this.pause = Integer.parseInt(s);
  145.       }
  146.  
  147.       s = ((Applet)this).getParameter("text_pause");
  148.       if (s != null) {
  149.          this.textPause = Integer.parseInt(s);
  150.       }
  151.  
  152.       s = ((Applet)this).getParameter("horizontal_cells_number");
  153.       if (s != null) {
  154.          this.NWCells = Integer.parseInt(s);
  155.       }
  156.  
  157.       s = ((Applet)this).getParameter("vertical_cells_number");
  158.       if (s != null) {
  159.          this.NHCells = Integer.parseInt(s);
  160.       }
  161.  
  162.       s = ((Applet)this).getParameter("cells_spacing");
  163.       if (s != null) {
  164.          this.cellsSpacing = Integer.parseInt(s);
  165.       }
  166.  
  167.       s = ((Applet)this).getParameter("min_pause");
  168.       if (s != null) {
  169.          this.minPause = Integer.parseInt(s);
  170.       }
  171.  
  172.       s = ((Applet)this).getParameter("max_pause");
  173.       if (s != null) {
  174.          this.maxPause = Integer.parseInt(s);
  175.       }
  176.  
  177.       ((Component)this).setBackground(this.getColor("background_color"));
  178.       this.statusBarText = ((Applet)this).getParameter("status_bar_text");
  179.       s = ((Applet)this).getParameter("sound_name");
  180.       if (s != null) {
  181.          this.sound = ((Applet)this).getAudioClip(((Applet)this).getCodeBase(), s);
  182.       }
  183.  
  184.       s = ((Applet)this).getParameter("loop_sound");
  185.       if (s != null) {
  186.          if (s.equals("yes")) {
  187.             this.loopSound = true;
  188.          } else {
  189.             this.loopSound = false;
  190.          }
  191.       }
  192.  
  193.       s = ((Applet)this).getParameter("clic_sound_name");
  194.       if (s != null) {
  195.          this.clicSound = ((Applet)this).getAudioClip(((Applet)this).getCodeBase(), s);
  196.       }
  197.  
  198.       s = ((Applet)this).getParameter("enter_sound_name");
  199.       if (s != null) {
  200.          this.enterSound = ((Applet)this).getAudioClip(((Applet)this).getCodeBase(), s);
  201.       }
  202.  
  203.       this.link = ((Applet)this).getParameter("link");
  204.       s = ((Applet)this).getParameter("text_height");
  205.       if (s != null) {
  206.          this.textHeight = Integer.parseInt(s);
  207.       }
  208.  
  209.       this.textColor = this.getColor("text_color");
  210.       if (this.textColor == null) {
  211.          this.textColor = Color.white;
  212.       }
  213.  
  214.    }
  215.  
  216.    public Color getColor(String param) {
  217.       String s = ((Applet)this).getParameter(param);
  218.       if (s != null) {
  219.          if (s.substring(0, 1).equals("#")) {
  220.             s = s.substring(1);
  221.             int i = Integer.parseInt(s, 16);
  222.             return new Color(i);
  223.          } else {
  224.             return null;
  225.          }
  226.       } else {
  227.          return null;
  228.       }
  229.    }
  230.  
  231.    public final void paint(Graphics g) {
  232.       if (this.loaded) {
  233.          this.field_0.clearRect(0, 0, this.field_2, this.field_3);
  234.  
  235.          for(int i = 0; i < this.NHCells; ++i) {
  236.             for(int j = 0; j < this.NWCells; ++j) {
  237.                this.field_0.drawImage(this.image[this.mat[i][j]], j * (this.wiIm + this.cellsSpacing) + this.cellsSpacing, i * (this.heIm + this.cellsSpacing) + this.cellsSpacing, this);
  238.             }
  239.          }
  240.  
  241.          if (this.text != null) {
  242.             this.field_0.drawString(this.lines[this.field_4], (this.field_2 - this.wiText) / 2, this.field_3 / 2);
  243.          }
  244.  
  245.          g.drawImage(this.buffer, 0, 0, this);
  246.       }
  247.  
  248.    }
  249.  
  250.    public final void update(Graphics g) {
  251.       this.paint(g);
  252.    }
  253.  
  254.    public void start() {
  255.       if (this.thread == null) {
  256.          this.thread = new Thread(this);
  257.          this.thread.start();
  258.       }
  259.  
  260.    }
  261.  
  262.    public void stop() {
  263.       if (this.thread != null) {
  264.          this.thread = null;
  265.       }
  266.  
  267.       if (this.sound != null) {
  268.          this.sound.stop();
  269.       }
  270.  
  271.    }
  272.  
  273.    public void run() {
  274.       if (!this.loaded) {
  275.          for(this.field_1 = 0; ((Applet)this).getParameter("image" + Integer.toString(this.field_1 + 1)) != null; ++this.field_1) {
  276.          }
  277.  
  278.          if (this.NWCells == 0) {
  279.             this.NWCells = this.field_1;
  280.             this.NHCells = 1;
  281.          }
  282.  
  283.          this.mat = new int[this.NHCells][this.NWCells];
  284.          int n = 0;
  285.  
  286.          for(int i = 0; i < this.NHCells; ++i) {
  287.             for(int j = 0; j < this.NWCells; ++j) {
  288.                this.mat[i][j] = n++;
  289.                if (n >= this.field_1) {
  290.                   n = 0;
  291.                }
  292.             }
  293.          }
  294.  
  295.          this.image = new Image[this.field_1];
  296.          MediaTracker tracker = new MediaTracker(this);
  297.  
  298.          for(int i = 0; i < this.field_1; ++i) {
  299.             this.image[i] = ((Applet)this).getImage(((Applet)this).getCodeBase(), ((Applet)this).getParameter("image" + Integer.toString(i + 1)));
  300.             tracker.addImage(this.image[i], 0);
  301.          }
  302.  
  303.          try {
  304.             tracker.waitForAll();
  305.             this.loaded = !tracker.isErrorAny();
  306.          } catch (Exception e) {
  307.             System.out.println(e);
  308.          }
  309.  
  310.          if (!this.loaded) {
  311.             this.stop();
  312.          }
  313.       }
  314.  
  315.       if (this.text != null) {
  316.          int c = 0;
  317.  
  318.          int m;
  319.          for(m = 0; (c = this.text.indexOf("#", c)) != -1; ++m) {
  320.             ++c;
  321.          }
  322.  
  323.          if (m != 0) {
  324.             int[] index = new int[m];
  325.             this.lines = new String[m + 1];
  326.  
  327.             for(m = 0; (c = this.text.indexOf("#", c)) != -1; ++m) {
  328.                index[m] = c;
  329.                String line;
  330.                if (m == 0) {
  331.                   line = this.text.substring(0, index[0]);
  332.                } else {
  333.                   line = this.text.substring(index[m - 1] + 1, index[m]);
  334.                }
  335.  
  336.                this.lines[m] = line;
  337.                ++c;
  338.             }
  339.  
  340.             this.lines[m] = this.text.substring(index[m - 1] + 1);
  341.          } else {
  342.             this.lines = new String[1];
  343.             this.lines[0] = this.text;
  344.          }
  345.       }
  346.  
  347.       this.wiIm = this.image[0].getWidth(this);
  348.       this.heIm = this.image[0].getHeight(this);
  349.       this.buffer = ((Component)this).createImage(this.field_2, this.field_3);
  350.       this.field_0 = this.buffer.getGraphics();
  351.       int compteurText = 0;
  352.       if (this.text != null) {
  353.          this.field_0.setColor(this.textColor);
  354.          String fontName = ((Applet)this).getParameter("text_font");
  355.          if (fontName == null) {
  356.             fontName = "TimesRoman";
  357.          }
  358.  
  359.          int style = 1;
  360.          String s = ((Applet)this).getParameter("text_style");
  361.          if (s != null) {
  362.             if (s.equals("bold")) {
  363.                style = 1;
  364.             } else if (s.equals("italic")) {
  365.                style = 2;
  366.             } else if (s.equals("bold_italic")) {
  367.                style = 3;
  368.             } else {
  369.                style = 0;
  370.             }
  371.          }
  372.  
  373.          this.field_0.setFont(new Font(fontName, style, this.textHeight));
  374.          this.field_5 = this.field_0.getFontMetrics();
  375.          this.field_4 = 0;
  376.          this.wiText = this.field_5.stringWidth(this.lines[this.field_4]);
  377.       }
  378.  
  379.       int[][] compteur = new int[this.NHCells][this.NWCells];
  380.  
  381.       for(int i = 0; i < this.NHCells; ++i) {
  382.          for(int j = 0; j < this.NWCells; ++j) {
  383.             compteur[i][j] = 0;
  384.          }
  385.       }
  386.  
  387.       while(true) {
  388.          ((Component)this).repaint();
  389.  
  390.          try {
  391.             Thread.sleep((long)this.pause);
  392.  
  393.             for(int i = 0; i < this.NHCells; ++i) {
  394.                for(int j = 0; j < this.NWCells; ++j) {
  395.                   compteur[i][j] += this.pause;
  396.                   if (compteur[i][j] > this.minPause && (compteur[i][j] > this.maxPause || Math.random() < 0.025)) {
  397.                      this.mat[i][j] = (int)((double)this.field_1 * Math.random());
  398.                      compteur[i][j] = 0;
  399.                   }
  400.                }
  401.             }
  402.  
  403.             if (this.text != null) {
  404.                compteurText += this.pause;
  405.                if (compteurText > this.textPause) {
  406.                   compteurText = 0;
  407.                   ++this.field_4;
  408.                   if (this.field_4 >= this.lines.length) {
  409.                      this.field_4 = 0;
  410.                   }
  411.  
  412.                   this.wiText = this.field_5.stringWidth(this.lines[this.field_4]);
  413.                }
  414.             }
  415.          } catch (InterruptedException var8) {
  416.             this.stop();
  417.          }
  418.       }
  419.    }
  420.  
  421.    public URL giveURL(String url) {
  422.       try {
  423.          if (url.toUpperCase().startsWith("HTTP")) {
  424.             return new URL(url);
  425.          } else if (url.toUpperCase().startsWith("FTP")) {
  426.             int p = url.indexOf(":");
  427.             int p2 = url.indexOf(":", p + 1);
  428.             if (p2 != -1) {
  429.                url = url.substring(0, p + 3) + URLEncoder.encode(url.substring(p + 3, url.length()));
  430.             }
  431.  
  432.             p = url.indexOf("%40");
  433.             if (p != -1) {
  434.                url = url.substring(0, p) + "@" + url.substring(p + 3, url.length());
  435.             }
  436.  
  437.             return new URL(url);
  438.          } else {
  439.             return new URL(((Applet)this).getCodeBase(), url);
  440.          }
  441.       } catch (MalformedURLException e) {
  442.          System.out.println(e);
  443.          return null;
  444.       }
  445.    }
  446.  
  447.    public void mouseClicked(MouseEvent e) {
  448.    }
  449.  
  450.    public void mouseEntered(MouseEvent e) {
  451.       if (this.statusBarText != null) {
  452.          ((Applet)this).showStatus(this.statusBarText);
  453.       }
  454.  
  455.       if (this.enterSound != null) {
  456.          this.enterSound.play();
  457.       }
  458.  
  459.       if (this.link != null) {
  460.          ((Component)this).setCursor(new Cursor(12));
  461.       }
  462.  
  463.    }
  464.  
  465.    public void mouseExited(MouseEvent e) {
  466.       if (this.link != null) {
  467.          ((Component)this).setCursor(new Cursor(0));
  468.       }
  469.  
  470.    }
  471.  
  472.    public void mousePressed(MouseEvent e) {
  473.       if (this.clicSound != null) {
  474.          this.clicSound.play();
  475.       }
  476.  
  477.       if (this.link != null) {
  478.          String target = ((Applet)this).getParameter("target");
  479.          if (target == null) {
  480.             target = "_blank";
  481.          }
  482.  
  483.          URL u = this.giveURL(this.link);
  484.          ((Applet)this).getAppletContext().showDocument(u, target);
  485.       }
  486.  
  487.    }
  488.  
  489.    public void mouseReleased(MouseEvent e) {
  490.    }
  491. }
  492.